#include<vector>
#include<cstdio>
#include<string>
#include<iostream>
#include<string.h>
#include<algorithm>
using namespace std;
bool cmp(char *a,char *b){
    for(int i=0;i<5;i++){
        if(*(a+i)!=*(b+i)){return *(a+i)<*(b+i);}
    }
}
int N,K;
int main(){
    //freopen("in.txt","r",stdin);
    scanf("%d %d",&N,&K);
    vector<char*>ans[K+1];
    char name[40010][5];
    int cnt,course;
    for(int i=0;i<N;i++){
        scanf("%s %d",name[i],&cnt);
        for(int j=0;j<cnt;j++){
            scanf("%d",&course);
            ans[course].push_back(name[i]);
        }
    }
    for(int i=1;i<=K;i++){
        printf("%d %d\n",i,ans[i].size());
        sort(ans[i].begin(),ans[i].end(),cmp);
        for(int j=0;j<ans[i].size();j++){
            printf("%s\n",ans[i][j]);
        }
    }
}
